function [ cfg ] = buildEpochs_defaultCfg()



%SELECTMARKERLATENCIES Select markers from an eeglab EEG set between boundaries.
%   Usage: to select ambiguous sphere left responses:
%      selectMarkerLatencies(EEG, {'R-SC-L'}, {'S-SC-A'}, {'S-Rest-10'}, false, true)
%   Will select latencies of all R-SC-L markers that exist between S-SC-A
%   and S-Rest-10 (or the end of the EEG data).
%   - includeStart: The beginning of the datafile will be treated as an extra preBoundary
%   - includeEnd: The beginning of the datafile will be treated as an extra postBoundary
%   Usage: to select all markers of a certain type, without boundaries:
%      selectMarkerLatencies(EEG, {'S-SC-L' 'S-SC-R'}, {}, {}, true, true)


cfg.timelimits = [-5000 5000]; % [mintime maxtime] (ms) sub-epoch time limits

cfg.DatasetFilenames = {}; % Instead of the EEGlab datasets in subjectinfo, use these filenames

cfg.Output.AutogenerateFilenames = true; % Set this to false to use the prefix and directory below
cfg.Output.EpochsetFilenamePrefix = ''; % Prefix the output filename with this.
cfg.Output.EpochsetDirectory = ''; % Prefix the output filename with this.

cfg.Output.StoreInSubjectinfo = true; % When true, buildEpochs will rewrite the EpochData node in the subjectinfo
% Note, the created files will also show up in the output variable

cfg.SaveSubjectinfo = true;

% Define sets as cfg.SETNAME. ...
% The resulting epoched set is the sum of all conditions per set

%% Configuration for Sphere Response
% x.name = 'Sphere Response';
% x.description = '...';
% x.condition(1).function = 'pop_epoch'; %% Eeglab selector
% x.condition(1).functionCfg.eventTypes = {'R-SC-R' 'R-SC-L'};
% x.condition(1).include.Sphere = true;
% x.condition(1).include.SphereIntermittend = false;
% x.condition(1).include.SphereVoluntary = false;
% x.condition(1).include.FaceHouse = false;
% cfg.EpochDefinitions.SphereResponse = x;
% clear x;

%% Configuration for Sphere Ambiguous Response
x.name = 'Sphere Ambiguous Response';
x.description = '...';
% Define the first condition (for the sphere datasets)
% Indicate what function should be used to select epochs
x.condition(1).function = 'selectMarkerLatencies'; % Home made selector, see "help selectMarkerLatencies" for info..
x.condition(1).functionCfg.markersToFind = {'R-SC-L' 'R-SC-R'};
x.condition(1).functionCfg.preBoundary = {'S-SC-A'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
% or
% cfg.condition(1).function = 'pop_epoch'; %% Eeglab selector
% cfg.condition(1).functionCfg.eventTypes = {'R-SC-R' 'R-SC-L'};
% Indicate for what type of data this condition is valid.
x.condition(1).include.Sphere = true;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = false;
% Introduce the second condition (for the sphere voluntary datasets)
x.condition(2).function = 'selectMarkerLatencies'; % Home made selector, see "help selectMarkerLatencies" for info..
x.condition(2).functionCfg.markersToFind = {'R-SV-L' 'R-SV-R'};
x.condition(2).functionCfg.preBoundary = {'S-SV-A'};
x.condition(2).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(2).functionCfg.includeStart = false;
x.condition(2).functionCfg.includeEnd = true;
x.condition(2).include.Sphere = false;
x.condition(2).include.SphereIntermittend = false;
x.condition(2).include.SphereVoluntary = true;
x.condition(2).include.FaceHouse = false;
% Introduce the third condition (for the sphere intermittend datasets)
x.condition(3).function = 'selectMarkerLatencies'; % Home made selector, see "help selectMarkerLatencies" for info..
x.condition(3).functionCfg.markersToFind = {'R-SC-L' 'R-SC-R'};
x.condition(3).functionCfg.preBoundary = {'S-SC-A'};
x.condition(3).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(3).functionCfg.includeStart = false;
x.condition(3).functionCfg.includeEnd = true;
x.condition(3).include.Sphere = false;
x.condition(3).include.SphereIntermittend = true;
x.condition(3).include.SphereVoluntary = false;
x.condition(3).include.FaceHouse = false;
cfg.EpochDefinitions.SphereAmbiguousResponse = x;
clear x;

%% Configuration for Sphere Unambiguous Response
x.name = 'Sphere Unambiguous Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'R-SC-R' 'R-SC-L'};
x.condition(1).functionCfg.preBoundary = {'S-SC-U'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = true;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = false;
cfg.EpochDefinitions.SphereUnambiguousResponse = x;
clear x;

%% Configuration for Sphere Unambiguous Stimulus
x.name = 'Sphere Unambiguous Stimulus';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'S-SC-R' 'S-SC-L'};
x.condition(1).functionCfg.preBoundary = {};
x.condition(1).functionCfg.postBoundary = {};
x.condition(1).functionCfg.includeStart = true;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = true;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = false;
cfg.EpochDefinitions.SphereUnambiguousStimulus = x;
clear x;

%% Configuration for Sphere Voluntary Stimulus
x.name = 'Sphere Voluntary Stimulus';
x.description = '...';
x.condition(1).function = 'pop_epoch'; %% Eeglab selector
x.condition(1).functionCfg.eventTypes = {'S-SV-L'  'S-SV-R'};
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = true;
x.condition(1).include.FaceHouse = false;
cfg.EpochDefinitions.SphereVoluntaryStimulus = x;
clear x;

%% Configuration for Sphere Voluntary Wanted Response
x.name = 'Sphere Voluntary Wanted Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies'; % Home made selector, see "help selectMarkerLatencies" for info..
x.condition(1).functionCfg.markersToFind = {'R-SV-LW' 'R-SV-RW'};
x.condition(1).functionCfg.preBoundary = {'S-SV-LI'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = true;
x.condition(1).include.FaceHouse = false;
cfg.EpochDefinitions.SphereVoluntaryWantedResponse = x;
clear x;

%% Configuration for Sphere Voluntary Unwanted Response
x.name = 'Sphere Voluntary Unwanted Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies'; % Home made selector, see "help selectMarkerLatencies" for info..
x.condition(1).functionCfg.markersToFind = {'R-SV-LU' 'R-SV-RU'};
x.condition(1).functionCfg.preBoundary = {'S-SV-LI'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = true;
x.condition(1).include.FaceHouse = false;
cfg.EpochDefinitions.SphereVoluntaryUnwantedResponse = x;
clear x;

%% Configuration for Sphere Random
% % nrOfEpochsPerSet = ceil(minNrOfEpochs / length(sphereXSets));
% % for d = sphereXSets 
% %     EEG = pop_loadset('filename', subjectinfo.Datasets(d).PreprocessedFilename);
% %     EEG = eeg_checkset( EEG );
% %     % Randomly select epochs
% %     rndMarkerLats = sort( EEG.srate * (rand(nrOfEpochsPerSet, 1) * (EEG.xmax - 24)) + 12 ); % exclude first and last 12 seconds of the set
% x.name = 'Sphere Random';
% x.description = '...';
% x.condition(1).function = 'random'; %% Random latency selector
% x.condition(1).functionCfg.count = 25; %% 25 random latencies per dataset
% x.condition(1).include.Sphere = true;
% x.condition(1).include.SphereIntermittend = false;
% x.condition(1).include.SphereVoluntary = true;
% x.condition(1).include.FaceHouse = false;
% cfg.EpochDefinitions.SphereRandom = x;
% clear x;

%% Configuration for FaceHouse Response
% x.name = 'FaceHouse Response';
% x.description = '...';
% x.condition(1).function = 'pop_epoch'; %% Eeglab selector
% x.condition(1).functionCfg.eventTypes = {'R-FH-F' 'R-FH-H'};
% x.condition(1).include.Sphere = false;
% x.condition(1).include.SphereIntermittend = false;
% x.condition(1).include.SphereVoluntary = false;
% x.condition(1).include.FaceHouse = true;
% cfg.EpochDefinitions.FaceHouseResponse = x;
% clear x;

%% Configuration for FaceHouse Ambiguous Response
x.name = 'FaceHouse Ambiguous Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'R-FH-F' 'R-FH-H'};
x.condition(1).functionCfg.preBoundary = {'S-FH-A'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseAmbiguousResponse = x;
clear x;

%% FaceHouse Ambiguous Face Response
x.name = 'FaceHouse Ambiguous Face Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'R-FH-F'};
x.condition(1).functionCfg.preBoundary = {'S-FH-A'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseAmbiguousFaceResponses = x;
clear x; 

%% FaceHouse Ambiguous House Response
x.name = 'FaceHouse Ambiguous House Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'R-FH-H'};
x.condition(1).functionCfg.preBoundary = {'S-FH-A'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseAmbiguousHouseResponses = x;
clear x; 

%% Configuration for FaceHouse Unambiguous Response
x.name = 'FaceHouse Unambiguous Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'R-FH-F' 'R-FH-H'};
x.condition(1).functionCfg.preBoundary = {'S-FH-F' 'S-FH-H'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseUnambiguousResponse = x;
clear x;

%% Configuration for FaceHouse Unambiguous Face Response
x.name = 'FaceHouse Unambiguous Face Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'R-FH-F'};
x.condition(1).functionCfg.preBoundary = {'S-FH-F' 'S-FH-H'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseUnambiguousFaceResponse = x;
clear x;

%% Configuration for FaceHouse Unambiguous House Response
x.name = 'FaceHouse Unambiguous House Response';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'R-FH-H'};
x.condition(1).functionCfg.preBoundary = {'S-FH-F' 'S-FH-H'};
x.condition(1).functionCfg.postBoundary = {'S-Rest-10'};
x.condition(1).functionCfg.includeStart = false;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseUnambiguousHouseResponse = x;
clear x;

%% Configuration for FaceHouse Unambiguous Stimulus
x.name = 'FaceHouse Unambiguous Stimulus';
x.description = '...';
x.condition(1).function = 'selectMarkerLatencies';
x.condition(1).functionCfg.markersToFind = {'S-FH-F' 'S-FH-H'};
x.condition(1).functionCfg.preBoundary = {};
x.condition(1).functionCfg.postBoundary = {};
x.condition(1).functionCfg.includeStart = true;
x.condition(1).functionCfg.includeEnd = true;
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseUnambiguousStimulus = x;
clear x; 

%% Configuration for FaceHouse Unambiguous Face Stimulus
x.name = 'FaceHouse Unambiguous Face Stimulus';
x.description = '...';
x.condition(1).function = 'pop_epoch'; %% Eeglab selector
x.condition(1).functionCfg.eventTypes = {'S-FH-F'};
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseUnambiguousFaceStimulus = x;
clear x; 

%% Configuration for FaceHouse Unambiguous House Stimulus
x.name = 'FaceHouse Unambiguous House Stimulus';
x.description = '...';
x.condition(1).function = 'pop_epoch'; %% Eeglab selector
x.condition(1).functionCfg.eventTypes = {'S-FH-H'};
x.condition(1).include.Sphere = false;
x.condition(1).include.SphereIntermittend = false;
x.condition(1).include.SphereVoluntary = false;
x.condition(1).include.FaceHouse = true;
cfg.EpochDefinitions.FaceHouseUnambiguousHouseStimulus = x;
clear x; 

end